<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>家庭医生登录</title>
		<link rel="stylesheet" type="text/css" href="js/layui/css/layui.css"/>
	</head>
	<style type="text/css">
		/* html {-webkit-filter: grayscale(100%);} */
		*{
			margin: 0;
			padding: 0;
		}
		body{
			height: calc(100vh);
			background-image: url(img/login_b_img.png);
			background-size: cover;
		}
		
	</style>
	
	<body>
		<div class="layui-container">
			<div  class="layui-row">
				<div class="layui-col-md6 layui-col-lg-offset3" style="margin-top: 100px;">
					<!-- 标题 -->
					<div class="layui-input-block">
						 <div class="title" style="font-size: 2em;text-align: center;"><img src="img/logo.png" >家庭医生签约平台</div>
					</div>	
				</div>
				<div class="layui-col-md6 layui-col-lg-offset3" style="margin-top: 20px;">
					<div class="layui-form">
						<form class="layui-form ">
							<!-- 电话 -->
							<div class="layui-form-item" style="">
								<label class="layui-form-label">电话：</label>
								<div class="layui-input-block">
									<input type="tel" name="phone" class="layui-input" lay-verify="required|phone" lay-reqtext="电话号码不能空" placeholder="请输入电话" autocomplete="off"  />
								</div>
							</div>
							<!-- 密码 -->
							<div class="layui-form-item" style="">
								<label class="layui-form-label">密码：</label>
								<div class="layui-input-block">
									<input type="password" name="password" class="layui-input" lay-verify="required|password" lay-reqtext="密码不能空" placeholder="请输入密码" autocomplete="off" />
								</div>
							</div>
							<!-- 身份选择 -->
							<div class="layui-form-item">
							    <label class="layui-form-label">角色：</label>
							    <div class="layui-input-block">
							      <select name="roler" lay-verify="required" >
							        <option value="doctor">医生</option>
							        <option value="admin">管理员</option>
							      </select>
							    </div>
							  </div>
							<!-- submit -->
							<div class="layui-form-item" style="">
								<div class="layui-input-block">
									<input type="submit" id="submit"  lay-submit lay-filter="formDemo" class="layui-btn"  style="width: 100% ; background-color: #75c5dc;" value="登录"/>
								</div>
							</div>
							
							<div class="layui-col-md6 layui-col-lg-offset4" style="margin-top: 10px;">
								<a href="forget2.html" style=""><i class="layui-icon layui-icon-left"></i>忘记密码</a>
								<a href="reg.html" style="float: right;">注册<i class="layui-icon layui-icon-right"></i></a>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
		
		<script src="js/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/md5.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			layui.use(['layer', 'form', 'element'],function(){
				//加载layui表单元素
				var form = layui.form,
					layer = layui.layer,
					element = layui.element; 
				form.render();
				
				form.verify({
				    phone:[/(^$)|^1\d{10}$/,'请输入正确的手机号'],
					password: [/^[\S]{6,12}$/,'密码必须6到12位，且不能出现空格'],
				});
				
				form.on("submit(formDemo)", function (data) {
					 $.ajax({   
						url:'http://123.56.67.48:8080/login',
						contentType:'application/json',
						method:'POST',
						data:JSON.stringify({
							username : data.field.phone,//电话
							password : hex_md5(data.field.password),//密码
							identify : data.field.roler//身份
						}),
						success:function(res){
							console.log(res);
							var k = JSON.parse(res)
							if(k.code == 1 && k.msg =="admin"){
								window.location.href = "Admin/Admin_HomePage.html"
							}
							else if(k.code == 1){
									localStorage.setItem('FDSMS',data.field.phone);
									window.location.href = 'Doc/Docpage2.html';
								} else {
									layer.msg(k.msg);
								}
							},              
							error:function (res) {
								console.log("失败"); 
							}           
						}) ;   
	
					return false;
				});
				
				$('#reg').click(function(){
					layer.open({
						type: 2,
						title:"注册",
						area: ['800px', '500px'],
						content: 'reg.html'
					})
				})
			});
		</script>
	</body>
</html>
